﻿using Nop.Core;
using Nop.Core.Domain.Logistics;
using Nop.Core.Domain.Orders;
using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Nop.Services.Logistics
{
    [SpotshubStringConvertable]
    public class OrderInformation
    {
        public OrderInformation()
        {
            Locations = new List<LocationInformation>();
            CurrentLocationId = 0;
        }

        public bool OrderPaid { get; set; }
        public bool OrderCompleted { get; set; }
        public int? OrderId { get; set; }

        public int CurrentLocationId { get; set; }
        public List<LocationInformation> Locations { get; set; }

        public int? UserAddressId { get; set; }
        public bool? IsCommerce { get; set; }
        public int OrderKindId { get; set; }
    }


    public class LocationInformation
    {
        public LocationInformation()
        {
            Packages = new List<PackageInformation>();
        }

        public int PackageNumber { get; set; }
        public int AddressId { get; set; }
        public bool IsUserAddressPickup { get; set; }

        public int RegionId { get; set; }

        public int Id { get; set; }
        public int CurrentPackageId { get; set; }

        public int? PickupTimeWindowId { get; set; }
        public DateTime? PickupDate { get; set; }

        public bool? NoSignature { get; set; }
        public bool? CanDeliverOnSat { get; set; }
        public bool? CanDeliverOnSun { get; set; }
        public bool IsInterDistrict { get; set; }
        public bool IsResidential { get; set; }

        public string AddtionalInstruction { get; set; }

        public string OrderInfo { get; set; }

        public List<PackageInformation> Packages { get; set; }
    }

    public class PackageInformation
    {
        public int Id { get; set; }

        public int? ShipmentId { get; set; }
        public int? PackageId { get; set; }
        public string TrackingNumber { get; set; }

        public decimal? Length { get; set; }
        public decimal? Width { get; set; }
        public decimal? Height { get; set; }
        public int? DimensionMeasureId { get; set; }

        public decimal? Weight { get; set; }
        public int? WeightMeasureId { get; set; }

        public decimal? InsuranceValue { get; set; }

        public AddtionalAttributes AddtionalAttributes { get; set; }

        public string Comment { get; set; }

        public bool IsLettersize { get; set; }
        public bool IsCompactSize { get; set; }
        public bool IsFullSize { get; set; }

        public int? PackagePreset { get; set; }

        public int OrderKindId { get; set; }

        //[XmlIgnore]
        //public bool IsLettersize
        //{
        //    get
        //    {
        //        return
        //            !this.Height.HasValue &&
        //            !this.Width.HasValue &&
        //            !this.Length.HasValue &&
        //            !this.Weight.HasValue;
        //    }
        //    set
        //    {
        //        if (value)
        //        {
        //            Height = null;
        //            Width = null;
        //            Length = null;
        //            Weight = null;
        //        }
        //    }
        //}
    }
    public class PackageInformationItems
    {
        public PackageInformationItems()
        {
            Items = new List<ShoppingCartItem>();
        }
        public PackageInformation PackageInformation { get; set; }
        public IList<ShoppingCartItem> Items { get; set; }

    }

    public static class PackageInformationExtension
    {
        public static decimal GetTotalDim(this PackageInformation pkg)
        {
            return (pkg.Length ?? 0M) +
                (pkg.Width ?? 0M) +
                (pkg.Height ?? 0M);
        }
    }
}
